<?php
/**
 ***********************************************************************************************************************
 * 微快递账号服务
 ***********************************************************************************************************************
 */
namespace soa\account\user;

use soa\client;

/**
 * Class realname
 */
class realname extends client
{
    /**
     * 服务地址
     * @var string
     */
    public $service_url = 'http://account.core.kuaidihelp.com/';

    /**
     * 服务名称
     * @var string
     */
    protected $service_name = 'kuaidihelp_account';

	//添加或更新实名
    public function insert($userId,$platform,$realnameId,$isConn = false){
        return $this->post('v1/user/realname/insert', compact('userId','platform','realnameId','isConn'));
    }

	//获取实名
	public function info($userId,$platform = "c"){
		return $this->post('v1/user/realname/info', compact('userId','platform'));
	}

	//获取用户实名记录id
	public function getRealnameId($userId,$platform = "c"){
		$ret = $this->info($userId,$platform);
		if(!empty($ret) && is_array($ret) && isset($ret["realname_id"])){
			return $ret["realname_id"];
		}
		return null;
	}

	//根据实名记录id获取用户
	public function getUsers($realnameId){
		return $this->post('v1/user/realname/getUsers', compact('realnameId'));
	}

	//解析身份证图片信息
	public function analysisImg($imgPath,$isBack = false){
		return $this->post('v1/user/realname/analysisImg', compact('imgPath','isBack'));
	}

	//根据订单号获取用户实名记录id
	public function getRealnameIdByOrder($orderNo){
		return $this->post('v1/user/realname/getRealnameIdByOrder', compact('orderNo'));
	}

	/**
	 * 手机号码查询身份证信息及详细地址
	 * @param $mobile
	 * @return mixed|null
	 */
	public function getCInfoMobile($mobile)
	{
		$output = [];
		$user = new \soa\account\user();
		$userInfo = $user->getUserByName($mobile);	//根据用户名码获取微快递用户信息
		if(empty($userInfo) || empty($userInfo['id'])){return $output;}
		$isRealname = $this->info($userInfo['id']);		//获取实名  测试id：45862
		if($isRealname['realname_id'] && is_numeric($isRealname['realname_id'])){
			$idcard = \artisan\http::post('http://order.core.kuaidihelp.com/v1/realname/CRealName/getIdCard', ['idCardId'=>$isRealname['realname_id']]);	//获取用户常用寄件地址
			$deIdcard = json_decode($idcard,true);
			if($deIdcard['code'] == 0 && $deIdcard['data']){
				$output = array_merge($output,$deIdcard['data']);
			}
		}
		$address = $this->post('v1/user/address/getList', ['user_id'=>$userInfo['id']]);	//获取用户常用寄件地址
		if($address['totalCount'] > 0 && $address['list'][0]){
			$addressRow = $address['list'][0];
			$output = array_merge($output,[
				'sendPcd'=>implode('-',[$addressRow['address_province'],$addressRow['address_city'],$addressRow['address_county']]),
				'sendAddress'=>$addressRow['address_detail'],
			]);
		}
		return $output;
	}
}